function can_use_lottery(argument) {
	return this.getPerm().can_use_lottery;
};
var skill = {
	_getLotteryIDList: function() {
		if (!Array.isArray(this.lotterys)) {
			this.lotterys = []
			this.save();
		}
		return this.lotterys;
	},
	getLottery: function(lottery_id, is_with_visitor_map) {
		if (this._getLotteryIDList().indexOf(lottery_id) === -1) {
			throwCusError("指定抽奖活动不属于商家")
		}
		var lottery = BusLotteryCon.get(lottery_id);
		if (!lottery) {
			throwCusError("找不到指定抽奖活动")
		}
		if (is_with_visitor_map) {
			lottery._joiner_map = lottery.joiner_map;
		}
		return lottery;
	},
	getLotteryWidthWinnerListInfo: function(lottery_id, is_with_visitor_map) {
		if (this._getLotteryIDList().indexOf(lottery_id) === -1) {
			throwCusError("指定抽奖活动不属于商家")
		}
		var lottery = BusLotteryCon.get(lottery_id);
		if (!lottery) {
			throwCusError("找不到指定抽奖活动")
		}
		lottery = $Object.clone(lottery)
		if (is_with_visitor_map) {
			lottery._joiner_map = lottery.joiner_map;
		}
		lottery.awards.forEach(function(_award_item) {
			_award_item.winner_list_info = _award_item.winner_list.map(function(user_id) {
				return UserCon.get(user_id)
			});
		});
		return lottery;
	},
	getLotteryList: function(is_with_visitor_map) {
		return this._getLotteryIDList().map(function(lottery_id) {
			return BusLotteryCon.get(lottery_id, is_with_visitor_map);
		});
	},
	//带有详细奖品信息的
	getLotteryDetailList: function(is_with_visitor_map) {
		var lottery_list = this.getLotteryList(is_with_visitor_map);
		lottery_list = lottery_list.map(function(lottery) {
			return lottery.getDetail();
		});
		return lottery_list;
	},
	//新增抽奖活动
	addLottery: function(lottery_info) {
		lottery_info.bus_id = this._id;
		var lottery = new BusLotteryCon(lottery_info);
		var lottery_id_list = this._getLotteryIDList();
		lottery_id_list.unshift(lottery._id);
		this.lotterys = lottery_id_list;
		this.save();
		return lottery;
	},
	//修改抽奖活动信息
	updateLottery: function(lottery_id, lottery_info) {
		var lottery = this.getLottery(lottery_id);
		lottery.setInfo(lottery_info);
		return lottery;
	},
	removeLottery: function(lottery_id) {
		var lottery = this.getLottery(lottery_id);
		lottery.destroy();
		var lottery_id_list = this._getLotteryIDList();
		var _index = lottery_id_list.indexOf(lottery_id);
		lottery_id_list.splice(_index, 1);
		this.lotterys = lottery_id_list;
		this.save();
	},
};
//权限限制注入
// Object.keys(skill).forEach(function(method_name) {
// 	skill[method_name] = skill[method_name].perm(can_use_lottery, "权限不足， 需开通成高级VIP才能使用")
// });
skill.canLottery = can_use_lottery;


module.exports = skill;

var db = require("../db/index");
var DomainCon = require("../domain/_con");
var GoodsCon = require("../goods/_con");
var UserCon = require("../../core/user/_con");
var BusCon = require("../../core/bus/_con");
var BusLotteryCon = require("../bus.lottery/_con");
var AchCon = require("../ach/_con");
var ClassifyCon = require("../bus.classify/_con");
var TagCon = require("../bus.tag/_con");
var LeagueCon = require("../league/_con");
var BuffCon = require("../buff/_con");
var BusUserBindCon = require("../bus_user_bind/_con");
var BusGuideCon = require("../bus.guide/_con");
var CommentCon = require("../comment/_con");
var config = require("../_include/config");
var data_cut = require("../_include/data_cut");
var helper = require("../_include/helper");
var md5 = require("../_include/md5");
var $Object = require("../_include/$.Object");
var $Array = require("../_include/$.Array");
var tld = require('tldjs');
var fs = require("fs");
var Fiber = require('fibers');